package com.hrma.controller;

import com.github.pagehelper.Page;
import com.hrma.entity.*;
import com.hrma.services.AdminService;
import com.hrma.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {
    private final AdminService adminService;

    public AdminController(AdminService adminService) {
        this.adminService = adminService;
    }

    @PostMapping("/add")
    public Result<String> add( String num) {
        log.debug("收到add请求，请求参数：{}", num);
        adminService.add(num);
        return Result.ok(num);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable int id) {
        log.debug("收到delete请求，请求参数：{}", id);
        adminService.delete(id);
        return Result.ok(null);
    }

    @PostMapping("/list")
    public Result<ListWithCount<Admin>> getList(@RequestBody AdminDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<Admin> res = adminService.getList(data);

        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }
}
